//
//  MovieDetailTableViewCell.m
//  Streaming
//
//  Created by 韩一博 on 15/6/26.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "MovieDetailTableViewCell.h"
#define allSize 10
@implementation MovieDetailTableViewCell

- (void)dealloc
{
    [self.timeLabel release];
    [self.nameLabel release];
    [self.photoImageView release];

    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        if (WIDTH == 320 && HEIGHT == 568) {
            [self cell5];
        }
        if (WIDTH == 414 && HEIGHT == 736) {
            [self cellPlus];
        }
        if (WIDTH == 375 && HEIGHT == 667){
            [self cell6];
        }

    }
    return self;
}

- (void)cell5
{
    self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(allSize, allSize, (self.contentView.frame.size.width - 2 * allSize) / 2 - 10, 2 * self.contentView.frame.size.height )];
    [self.photoImageView setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.photoImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize - 10, allSize + 10, (self.contentView.frame.size.width - 2 * allSize) / 2, self.contentView.frame.size.height+10)];
    self.nameLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.nameLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize, self.contentView.frame.size.height + allSize + 10, (self.contentView.frame.size.width - 2 * allSize) / 2, self.contentView.frame.size.height)];
    self.timeLabel.font = [UIFont boldSystemFontOfSize:14];
    [self.timeLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.timeLabel];
    
    [self.timeLabel release];
    [self.nameLabel release];
    [self.photoImageView release];
    
    
}


- (void)cell6
{
    self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(allSize, allSize, (self.contentView.frame.size.width - 2 * allSize) / 2, 2 * self.contentView.frame.size.height )];
    [self.photoImageView setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.photoImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize, allSize, (self.contentView.frame.size.width - 2 * allSize) / 2, self.contentView.frame.size.height)];
    [self.nameLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize, self.contentView.frame.size.height + allSize, (self.contentView.frame.size.width - 2 * allSize) / 2, self.contentView.frame.size.height)];
    [self.timeLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.timeLabel];
    
    
    [self.timeLabel release];
    [self.nameLabel release];
    [self.photoImageView release];

}

- (void)cellPlus
{
    NSLog(@"25");
    
    self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(allSize, allSize-10, (self.contentView.frame.size.width - 2 * allSize) / 2, 2 * self.contentView.frame.size.height )];
    [self.photoImageView setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.photoImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize, allSize, 220, self.contentView.frame.size.height)];
    [self.nameLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photoImageView.frame.size.width + 3 * allSize, self.contentView.frame.size.height + allSize, (self.contentView.frame.size.width - 2 * allSize) / 2, self.contentView.frame.size.height)];
    [self.timeLabel setBackgroundColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.timeLabel];
    
    [self.timeLabel release];
    [self.nameLabel release];
    [self.photoImageView release];

}

- (void)setMovieDetail:(MovieDetail *)movieDetail
{
    if (_movieDetail != movieDetail) {
        [_movieDetail release];
        _movieDetail = [movieDetail retain];
        
    }
    NSURL *url = [NSURL URLWithString:movieDetail.movieImageView];
    [self.photoImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"111111.png"]];
    
    self.nameLabel.text = [NSString stringWithFormat:@"%@", movieDetail.nameLabel];
    self.nameLabel.numberOfLines = 2;
    [self.nameLabel sizeToFit];
    
    NSInteger minutes = (NSInteger)movieDetail.length / 60;
    NSInteger seconds = (NSInteger)movieDetail.length % 60;
    self.timeLabel.text = [NSString stringWithFormat:@"片长：%02ld分%02ld秒", minutes, seconds];
    self.timeLabel.textColor = [UIColor lightGrayColor];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
